home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4790 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: gcc bug w/getenv? (running Linux)
  5. Date: 6 Feb 1996 19:14:51 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4f8ueb$qcd@solutions.solon.com>
  8. References: <4f8sue$84d@newsflash.concordia.ca>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <4f8sue$84d@newsflash.concordia.ca>,
  12. Angus C. March <ac_march@ece.concordia.ca> wrote:
  13. >I seem to suffer this bizarre bug in gcc-2.6.3, that run on Linux 1.2.13. I
  14. >tried to assigning a getenv() pointer to a varaible of type char *, but I
  15. >got a warning about assigning an integer to a pointer. I tried this little
  16. >experiement:
  17.  
  18. >#include <stdio.h>
  19.  
  20. >int main()
  21. >{
  22. >        char *temp;
  23. >        int thingi;
  24.  
  25. >temp = (char *)getenv("TERM");
  26.  
  27. Hmm.  You're calling getenv, which returns (char *), but there's no
  28. prototype in scope.  Perhaps you'd like to include <stdlib.h>?
  29.  
  30. >thingi = getenv("TERM");
  31.  
  32. Assigning a pointer to an int with no cast...
  33.  
  34. >        printf("getenv(term): %s\ntemp: %s\nthingi: %s\n", getenv("TERM"),
  35. >temp, thingi);
  36.  
  37. Hmm.  Printf with an argument (thingi) not matching the format type.
  38.  
  39. >        return 0;
  40. >}
  41. >The results where facinating:
  42. >getenv(term): vt100
  43. >temp: vt100
  44. >thingi: vt100
  45. >    Is this a bona fide bug?
  46.  
  47. Nope.  Your code is illegal on three counts, the first of which is your
  48. mistake.  It looks like gcc/linux/x86 uses the same representation
  49. for pointers and ints.
  50.  
  51. Remember to include relevant headers.
  52.  
  53. (Also, don't print a getenv() without cheking for NULL.  Also, use -Wall,
  54.  so the first use of getenv() warns you that you're calling it with no
  55.  prototype in scope.)
  56.  
  57. -s
  58. -- 
  59. Peter Seebach - seebs@solon.com - Copyright 1995 Peter Seebach.
  60. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  61. Using trn?  Weird new newsgroup problem?  I know the fix!  Email me!
  62. The *other* C FAQ - ftp taniemarie.solon.com /pub/c/afq - Not A Flying Toy
  63.